﻿
    <div class="ui-widget ui-corner-all">
        <div class="ui-widget-header">
            <i class="fa fa-home fa-fw"></i>Home
        </div>
        <div class="ui-widget-content">
           
            

                <div class="ui-widget ui-corner-all" id="LoginForm" style="width:250px;">
                    <div class="ui-widget-header">
                        Login
                    </div>
                    <div class="ui-widget-content my-form">
                        <p>
                            Username: <input type="text" id="Username" />
                        </p>
                        <p>
                            Password: <input type="password" id="Password1" />
                        </p>
                        <p class="my-button-row">
                            <span class="button" data-icon="fa-lock" onclick="TryLogin();">Login</span>
                        </p>
                    </div>
                </div>

           
           
            <p>
                Galactic is an interactive HTML5 application to analyze and visualize galatic data sets.
            </p>

            <p>            
                <a href="https://galactic.codeplex.com" target="_blank" class="">Galactic Project Page (Codeplex.com)</a><span class="ui-icon ui-icon-extlink ilb"/>
            </p>
            
           
            

        </div>
    </div>



<script type="text/javascript">

    ///<reference path="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js" />
    ///<reference path="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" />
    ///<reference path="js/lib.js" />
    ///<reference path="js/md5.js" />

    $(document).ready(function ()
    {
        console.log("home");
        if (GetUsername() != null)
            $("#LoginForm").hide();
    });

   
    function ValidateLoginForm()
    {
        $("#LoginForm input").removeClass("ui-state-error");
        var isValid = true;

        if (FieldIsEmpty("#Username"))
            isValid = false;

        if (FieldIsEmpty("#Password1"))
            isValid = false;

        return isValid;

    }
       

    function TryLogin()
    {
        if (ValidateLoginForm())
        {
            var pwHash = CryptoJS.MD5($("#Password1").val()).toString();

            GetJsonSproc("usp_Login",
                {
                    PasswordHash: pwHash,
                    Username: $("#Username").val()
                },
                function (res)
                {
                    if (res == "")
                    {
                        alert("Login Failure");
                        $("#LoginForm input").addClass("ui-state-error");
                        $("#Password1").val("").focus();
                    }
                    else
                    {
                        localStorage.setItem("Username", res[0]["Username"]);
                        localStorage.setItem("UserId", res[0]["id"]);
                        localStorage.pushoverKey = res[0].PushoverKey;
                        localStorage.ClientUniqueId = res[0].ClientUniqueId;
                        $("#LoginForm").fadeOut("fast");
                        UpdateLoggedInUserName();
                        UserJustLoggedIn();
                    }
                });

        }
    }
  


</script>

